home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 22 / Cream of the Crop 22.iso / program / eflibpt4.zip / DEMO / DATATYPE / ARRAYLST.PAS next >
Pascal/Delphi Source File  |  1996-08-18  |  2KB  |  49 lines

  1. { Borland Pascal Extended Function Library - EFLIB (C) Johan Larsson, 1996
  2.   Demonstration; array list with dynamic allocation
  3.  
  4.   EFLIB IS PROTECTED BY THE COPYRIGHT LAW AND MAY NOT BE COPIED, SOLD OR
  5.   MANIPULATED. FOR MORE INFORMATION, SEE PROGRAM MANUAL! THIS DEMONSTRAT-
  6.   ION PROGRAM MAY FREELY BE USED AND DISTRIBUTED.                          }
  7.  
  8.  
  9. uses EFLIBDEF, EFLIBINI, EFLIBBAS, EFLIBDAT;
  10.  
  11. const NumberOfElements = 100;
  12.  
  13. var MyList : ArrayListObjectType; Timer : TimerObjectType;
  14.     Word1, Word2 : word;
  15.  
  16.  
  17. begin
  18.      Randomize; Timer.Initialize;
  19.  
  20.      WriteLn ('* Array list with dynamic allocation *');
  21.  
  22.      { Generate an array list with 100 entries an then display them all }
  23.  
  24.      with MyList do begin
  25.           { Initialize a array list with a fixed number of elements }
  26.           Initialize (NumberOfElements, SizeOf(Word1));
  27.                      { Elements }       { Element size }
  28.  
  29.           { Sequential writing to array (write numbers 1 ... n in reversed
  30.             order) }
  31.           for Word2 := 1 to NumberOfElements do
  32.               Add (Word2);
  33.  
  34.           { Reverse element order (swap first and last element and decrement
  35.             interval until all elements have been swapped) }
  36.           for Word2 := 1 to Elements div 2 do
  37.               Swap (Word2, Succ(Elements - Word2));
  38.  
  39.           { Display entries }
  40.           for Word2 := Elements downto 1 do Write (Word(ElementPointer(Word2)^):8);
  41.  
  42.           WriteLn;
  43.           WriteLn ('Used ', Elements, ' elements of an array with storage capacity of ', Capacity, ' elements.');
  44.           Intercept;
  45.      end;
  46.  
  47.      with Timer do begin WriteLn (StringMS); Intercept; end;
  48.      if GlobalDataError then WriteLn ('Error(s) reported!');
  49. end.